#/usr/bin/python
#encoding:utf-8
import time
import csv
from LanchTime.LanchTimeTest import LanchTime

# 控制层类
class Controller():
    def __init__(self, count):
        self.app = LanchTime()
        self.counter = count
        self.alldata = [("timestamp","elapsedtime")]
    #单次测试过程
    def testprocess(self):
        self.app.LaunchApp()
        time.sleep(5)
        elpasedtime = self.app.GetLaunchTime()
        self.app.StopApp()
        time.sleep(3)
        currenttime = self.getCurrentTime()
        self.alldata.append((currenttime, elpasedtime))

    #多次测试过程
    def run(self):
        while self.counter > 0:
            self.testprocess()
            self.counter = self.counter - 1
    # 获取当前时间戳
    def getCurrentTime(self):
        currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        return currentTime

    # 实现数据存储
    def SaveDateToCsv(self):
        with open('startTime.csv','wb',encoding='UTF-8') as datacsv:
            csvwriter = csv.writer(datacsv, dialect=("excel"))
            csvwriter.writerow(self.alldata)
            datacsv.close()



